package cn.tradewin.advisor.pages.project;

import java.util.List;

import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;

import cn.tradewin.advisor.persist.model.Account;
import cn.tradewin.advisor.persist.model.Project;
import cn.tradewin.advisor.persist.model.Task;
import cn.tradewin.advisor.persist.services.ProjectService;

public class ProjectDetail {

	@SessionState
	private Project target;
	
	@Property
	private Integer projectId;

	@Property
	private Project project;

	@Property
	private List<Task> projectTasks;

	@Property
	private Task projectTask;

	@Property
	private List<Account> projectResources;

	@Property
	private Account projectResource;

	@Inject
	private ProjectService taskService;
	
	@Inject
	private ProjectService projectService;

	@Environmental
	private JavaScriptSupport javaScriptSupport;

	void onActivate(Integer projectId) {
		this.projectId = projectId;
		target.setId(projectId);
	}

	Integer onPassivate() {
		return this.projectId;
	}

	// @Property
	// private List<Risk> projectRish;

	void setupRender() {
		project = projectService.findProject(projectId);
		projectResources = taskService.getAllProjectResources(projectId);
		projectTasks = taskService.getAllProjectTasks(projectId);
	}

	// The code

	void afterRender() {
		javaScriptSupport.require("bootstrap/tab");
	}
}